﻿unit SysOrganizationService;

interface
{$I ../Config.inc}
uses
  FastMM4,
  FastMove,
  System.SysUtils,
  System.Classes,
  System.Types,
  Winapi.Windows,
  Data.DB,
  Data.Win.ADODB,
  Datasnap.DBClient,
  Datasnap.Provider,
  {$IFDEF UNICODE}
  AnsiStrings,
  {$ENDIF }
  QBParcel,
  DllSpread,
  Generics.Collections,
  DateUtils,
  QJson,
  UserConnection,
  DBAccessor,
  DllPlugin,
  StrUtils,
  SKSOFTComm,
  SysOrganizationModel,
  SysOrganizationBLL;
  
type

  TSysOrganizationService = class(TSysOrganizationBLL)
  private

  protected

  public
  {$IFDEF SERVER}
    function BeforeTreatment(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
    function BeforeTreatment(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;

    function BeforeCheck(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
    function BeforeCheck(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;

    function Check(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
    function Check(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;

    function BeforeExecute(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
    function BeforeExecute(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;

    function AfterTreatment(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
    function AfterTreatment(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;override;
  {$ENDIF}

    function LoadAll(const iItems:TSysOrganizationList; out oError:string; const iJustUse:Boolean=False):Boolean;
    function LoadById(const iOrgId:string; const iItem:TSysOrganization; out oError:string):Boolean;
  end;
  
implementation

{$IFDEF SERVER}
function TSysOrganizationService.BeforeTreatment(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.BeforeTreatment(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.BeforeCheck(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.BeforeCheck(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.Check(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.Check(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.BeforeExecute(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.BeforeExecute(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.AfterTreatment(const iItem:TSysOrganization; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TSysOrganizationService.AfterTreatment(const iItems:TSysOrganizationList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;
{$ENDIF}

function TSysOrganizationService.LoadAll(const iItems:TSysOrganizationList; out oError:string; const iJustUse:Boolean):Boolean;
var
  Condition,OrderBy:string;
begin
  if (iItems<>nil) then
  begin
    if iJustUse then
    begin
      Condition:=Format(string('%s=1'),[TSysOrganizationModel.cOrgStatusKey]);
    end else begin
      Condition:='1=1';
    end;
    OrderBy:=TSysOrganizationModel.cOrgIdKey+' ASC';

    if not LoadByCondition(iItems,Condition,oError,OrderBy) then
    begin
      Result:=False;
      Exit;
    end;
  end else begin
    oError:=Format(string('调用TSysOrganizationService.LoadAll方法失败！错误内容:传入的iItems为空!'),[]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;

function TSysOrganizationService.LoadById(const iOrgId:string; const iItem:TSysOrganization; out oError:string):Boolean;
var
  Condition:string;
begin
  if not SameStr(Trim(iOrgId),EmptyStr) and (iItem<>nil) then
  begin
    Condition:=Format(string('%s=''%s'''),[TSysOrganizationModel.cOrgIdKey,iOrgId]);

    if not LoadByCondition(iItem,Condition,oError) then
    begin
      Result:=False;
      Exit;
    end;
  end else begin
    oError:=Format(string('调用TSysOrganizationService.LoadById方法失败！错误内容:传入的iOrgId或者iItem为空!'),[]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
  
end.
